﻿<UserControl x:Class="AppFabric.Admin.Client.Controls.ConfigurationUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:lex="http://schemas.root-project.org/xaml/presentation"
             xmlns:model="clr-namespace:AppFabric.Admin.Client.Core.Model;assembly=AppFabric.Admin.Client.Core"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="400"
             DataContext="{Binding Configuration, Source={StaticResource Locator}}">

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <cmd:EventToCommand Command="{Binding ControlLoadedCommand, Mode=OneWay}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Skins/AppStyles.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <DataTemplate x:Key="EnvironmentComboBoxDataTemplate" DataType="model:Environment">
                <WrapPanel Height="48">
                    <Image Source="\Resources\environment.png" Width="48" Height="48" />
                    <StackPanel Margin="10 0 10 0">
                        <TextBlock Text="{Binding Name}" Style="{StaticResource ResourceKey=TextBlockSecondLevelTitleStyle}" />
                        <TextBlock Text="{Binding Description}" Margin="0 3 0 0" Foreground="Gray" />
                    </StackPanel>
                </WrapPanel>
            </DataTemplate>

            <Style x:Key="GridViewColumnTextBlockStyle" TargetType="TextBlock">
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
            
            <Style x:Key="EnvironmentComboxBoxStyle" TargetType="ComboBox">
                <Setter Property="Height" Value="48" />
                <Setter Property="Width" Value="359" />
                <Setter Property="HorizontalAlignment" Value="Left" />
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="BorderBrush" Value="DarkGray" />
            </Style>

            <Style x:Key="DataGridRowStyle" TargetType="DataGridRow">
                <Setter Property="Height" Value="20" />
                <Setter Property="HorizontalContentAlignment" Value="Left" />
                <Setter Property="VerticalContentAlignment" Value="Center" />
                <Setter Property="Padding" Value="5 5 0 0" />
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <StackPanel>
        <Label Content="{lex:LocText Key=EnvManagementTitle, Dict=Resources, Assembly=AppFabric.Admin.Client}" Style="{StaticResource ResourceKey=LabelFirstLevelTitleStyle}" />
        <ComboBox x:Name="EnvironmentsComboBox" ItemsSource="{Binding Items, Mode=OneWay}" SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}" ItemTemplate="{DynamicResource ResourceKey=EnvironmentComboBoxDataTemplate}" SelectedValue="{Binding SelectedValue, Mode=OneWayToSource}" Style="{DynamicResource ResourceKey=EnvironmentComboxBoxStyle}"  />
        <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Margin="0 5 0 0">
            <Button x:Name="AddEnvironmentButton" Command="{Binding AddEnvironmentCommand}" Style="{StaticResource ResourceKey=TextImageButton24Style}">
                <WrapPanel>
                    <Image Source="/Resources/add.png" />
                    <Label Content="{lex:LocText Key=AddEnvironmentLabel, Dict=Resources, Assembly=AppFabric.Admin.Client}" Style="{StaticResource ResourceKey=InnerTextButtonStyle}" />
                </WrapPanel>
            </Button>
            <Button x:Name="RemoveEnvironmentButton" Command="{Binding RemoveEnvironmentCommand}" Style="{StaticResource ResourceKey=TextImageButton24Style}" Margin="5 0 0 0">
                <WrapPanel>
                    <Image Source="/Resources/remove.png" />
                    <Label Content="{lex:LocText Key=RemoveEnvironmentLabel, Dict=Resources, Assembly=AppFabric.Admin.Client}" Style="{StaticResource ResourceKey=InnerTextButtonStyle}" />
                </WrapPanel>
            </Button>
            <Button x:Name="EditEnvironmentButton" Command="{Binding EditEnvironmentCommand}" Style="{StaticResource ResourceKey=TextImageButton24Style}"  Margin="5 0 0 0">
                <WrapPanel>
                    <Image Source="/Resources/modify.png" />
                    <Label Content="{lex:LocText Key=EditEnvironmentLabel, Dict=Resources, Assembly=AppFabric.Admin.Client}" Style="{StaticResource ResourceKey=InnerTextButtonStyle}" />
                </WrapPanel>
            </Button>
        </StackPanel>
        <Grid x:Name="EnvironmentPropertiesGrid" Margin="0 10 0 0" IsEnabled="{Binding CanEditSelectedValue, Mode=OneWay}">
            <Grid.Resources>
                <Style TargetType="{x:Type TextBox}">
                    <Setter Property="Margin" Value="0,0,0,4" />
                </Style>
                <Style TargetType="{x:Type Label}">
                    <Setter Property="Margin" Value="0,0,0,4" />
                </Style>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="75" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Label Grid.Row="0" Grid.Column="0" Content="{lex:LocText Key=NameLabel, Dict=Resources, Assembly=AppFabric.Admin.Client}" />
            <Label Grid.Row="1" Grid.Column="0" Content="{lex:LocText Key=DescriptionLabel, Dict=Resources, Assembly=AppFabric.Admin.Client}" />
            <Label Grid.Row="2" Grid.Column="0" Content="{lex:LocText Key=ClustersLabel, Dict=Resources, Assembly=AppFabric.Admin.Client}" />
            <StackPanel Grid.Row="3" Grid.Column="0">
                <Button x:Name="AddClusterButton" Command="{Binding AddClusterCommand}" Style="{StaticResource ResourceKey=ImageButton24x24Style}">
                    <Image Source="/Resources/add.png" />
                </Button>
                <Button x:Name="RemoveClusterButton" Command="{Binding RemoveClusterCommand}" Style="{StaticResource ResourceKey=ImageButton24x24Style}">
                    <Image Source="/Resources/remove.png" />
                </Button>
            </StackPanel>
            <TextBox x:Name="EnvNameTextBox"  Grid.Column="1" Grid.Row="0" MinWidth="280" Text="{Binding ElementName=EnvironmentsComboBox, Path=SelectedValue.Name, Mode=TwoWay}" />
            <TextBox x:Name="EnvDescriptionTextBox"  Grid.Column="1" Grid.Row="1" MinWidth="280" Text="{Binding ElementName=EnvironmentsComboBox, Path=SelectedValue.Description, Mode=TwoWay}" />

            <DataGrid x:Name="EnvClustersDataGrid"
                      ItemsSource="{Binding ElementName=EnvironmentsComboBox, Path=SelectedValue.Childs, Mode=TwoWay}"
                      Grid.Column="1" Grid.Row="3"
                      SelectedIndex="{Binding SelectedChildIndex, Mode=TwoWay}"
                      AutoGenerateColumns="False"
                      CanUserAddRows="False"
                      CanUserDeleteRows="False"
                      RowStyle="{DynamicResource ResourceKey=DataGridRowStyle}">
                <DataGrid.Columns>
                    <DataGridTextColumn Header="{lex:LocText Key=NameHeader, Dict=Resources, Assembly=AppFabric.Admin.Client}" Binding="{Binding Name}" MinWidth="75" />
                    <DataGridTextColumn Header="{lex:LocText Key=AdminServicesHeader, Dict=Resources, Assembly=AppFabric.Admin.Client}" Binding="{Binding BaseServicesUri}" MinWidth="200" />
                </DataGrid.Columns>
            </DataGrid>


            <Button x:Name="SaveEnvironmentButton" Grid.Row="4" Grid.Column="0" Command="{Binding SaveEnvironmentCommand}" Margin="0 10 0 0" Style="{StaticResource ResourceKey=TextImageButton28Style}">
                <WrapPanel>
                    <Image Source="/Resources/save.png" />
                    <Label Content="{lex:LocText Key=SaveLabel, Dict=Resources, Assembly=AppFabric.Admin.Client}" Style="{StaticResource ResourceKey=InnerTextButton28Style}" />
                </WrapPanel>
            </Button>
        </Grid>
    </StackPanel>
</UserControl>
